package com.ysjl.intentservice;

import android.app.IntentService;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

/**
 * Created by Administrator on 2017/10/9.
 */

public class MyIntentService extends IntentService{

    LocalBroadcastManager localBroadcastManager;
    int i=0;

    public MyIntentService(){
        super("my");
    }

    /**
     * Creates an IntentService.  Invoked by your subclass's constructor.
     *
     * @param name Used to name the worker thread, important only for debugging.
     */
    public MyIntentService(String name) {
        super(name);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        localBroadcastManager = LocalBroadcastManager.getInstance(this);
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
        while (true){

            Log.i("mylog","onHandleIntent");
            Intent intent1 = new Intent();
            intent1.putExtra("data",(i++)+"");
            intent1.setAction("end");
            localBroadcastManager.sendBroadcast(intent1);
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }


}
